<template>
	<view>
		<!-- 头部标题 -->
		<view class="cu-bar bg-white">
			<view class="action sub-title">
				<text class="text-xl text-bold text-green">作业列表</text>
				<text class="bg-green"></text>
				<!-- last-child选择器-->
			</view>
		</view>
		<!-- 头部标题 end -->

		<view @click.native="toWorkUploadPage(item)" style="width: 100%;margin-bottom: 20upx;" class="shadow-warp" v-for="(item,index) in WorkdData"
		 :key="index">

			<view class="bg-white" style="display: flex;padding: 20upx;">

				<image src="../../static/logo.png" style="height: 150upx;width: 150upx;border-radius: 20upx;"></image>

				<view style="margin-left: 20upx;display: flex;flex-direction: column;width: 75vw;">
					<view class="" style="display: flex;">
						<text class="text-cut" style="font-weight: 550;width: 60vw;">{{item.workName}}</text>
						<text class="" :style="'font-weight: 550;'">{{item.status==0?'未完成':'已完成'}}</text>
					</view>

					<view class="" style="margin-top: 50upx;display:flex;justify-content: space-between;align-items: center;">
						<text>共{{item.num}}到题目</text>
						<text style="margin-top: 5upx;">{{item.createdAt}}</text>
						<text style="color: red;">{{item.score}}分</text>
					</view>

				</view>

			</view>


		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				WorkdData: ''
			}
		},
		onShow() {
			this.getWorkdData()
		},
		methods: {
			// 作业数据
			getWorkdData() {
				uni.showLoading({
					title: "数据加载中...",

				})

				var classId = uni.getStorageSync('clazzId')
				var studentId = uni.getStorageSync('user_info').id
				var _this = this

				uni.request({
					url: _this.api + "work/list",
					data: {
						clazzId: classId,
						uid: studentId
					},
					header: {
						"content-type": "application/x-www-form-urlencoded"
					},
					method: "POST",
					success: (res) => {
						uni.hideLoading();
						_this.WorkdData = res.data.data;
						console.log(res);
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							title: "作业数据获取失败！请稍后在试~~",
							duration: 1000,
							icon: "none"
						})
					}

				})
			},

			toWorkUploadPage: function(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/work/work?id='+item.workId,
				});
			}
		}
	}
</script>

<style>

</style>
